var app = getApp();
// pages/change/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userScore: 0,
        studyTime: '04小时02分',
        studyLessionTime: 1,
        studyDays: '12',
        user: wx.getStorageSync('user')
    },
    timer: null,
    setAnmiteScore(score) {
        clearInterval(this.timer);
        this.timer = setInterval(() => {
            let userScore = this.data.userScore;
            if (Math.abs(score - userScore) < 1) {
                userScore = score;
                clearInterval(this.timer);
            }
            this.setData({
                userScore: (userScore == score ? 0 : userScore < score ? 1 : -1) + userScore
            })
        }, 30);
    },
    onLoad() {
    },
    onShow() {
        // 设置 分数
        setTimeout(this.setAnmiteScore, 300, (app.globalData.change.lastTestScore || this.data.user.lastScore || 0));
        wx.$ajax.getUserInfo({}, {isToken: true})

            .then(({data: {data, msg, status}, header, statusCode, errMsg}) => {
                if (status === '0') {
                    this.setData({
                        user: data.user
                    });
                    wx.setStorageSync('user', data.user);
                } else {
                    console.log('请求失败');
                }
            })

    }
})